package com.example.androidproject.base;

import android.util.Log;
import android.widget.Toast;

import androidx.annotation.ColorRes;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.SimpleItemAnimator;

import com.example.androidproject.interfaces.DataListener;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
public class BaseFragment extends Fragment {
    public void initRecyclerView(RecyclerView pRecyclerView, SmartRefreshLayout pRefreshLayout, DataListener pDataListener) {
        if (pRecyclerView != null) {
            pRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
            //将recycleview的出场动画禁掉，防止刷新闪烁
            ((SimpleItemAnimator)pRecyclerView.getItemAnimator()).setSupportsChangeAnimations(false);
        }
//        if (pRefreshLayout != null && pDataListener != null) {
//            pRefreshLayout.setOnRefreshListener(refreshLayout -> pDataListener.dataType(LoadTypeConfig.REFRESH));
//            pRefreshLayout.setOnLoadMoreListener(refreshLayout -> pDataListener.dataType(LoadTypeConfig.MORE));
//        }

    }

    public void showLog(Object content) {
        Log.e("睚眦", content.toString());
    }

    public void showToast(Object content) {
        Toast.makeText(getContext(), content.toString(), Toast.LENGTH_SHORT).show();
    }

    public int setColor(@ColorRes int pColor){
        return ContextCompat.getColor(getContext(),pColor);
    }


    public void setSmartListener(SmartRefreshLayout smartRefreshLayout, DataListener dataListener) {
//        smartRefreshLayout.setOnRefreshLoadMoreListener(new OnRefreshLoadMoreListener() {
//            @Override
//            public void onLoadMore(@NonNull RefreshLayout refreshLayout) {
//                dataListener.dataType(LoadTypeConfig.MORE);
//            }
//
//            @Override
//            public void onRefresh(@NonNull RefreshLayout refreshLayout) {
//                dataListener.dataType(LoadTypeConfig.REFRESH);
//            }
//        });
    }
}
